﻿using System;
using System.Collections.Generic;
using Domain.Dummies;
using Domain.Dummies.Dtos;
using Domain.Dummies.Dtos.Definitions;
using Domain.Dummies.Dtos.Collections;
using System.Linq;
using AutoMapper;

namespace Services.Dummies.DeaneryService
{
    public class DummyDeaneryService : IDeaneryService
    {
        public DummyDeaneryService()
        {
            Mapper.CreateMap<GroupDto, GroupBaseDto>();
            Mapper.CreateMap<ExamWithSubjectAndTeacherDto, ExamDto>()
                .ForMember(dst => dst.SubjectGuid, opt => opt.MapFrom(src => src.Subject.Id))
                .ForMember(dst => dst.TeacherGuid, opt => opt.MapFrom(src => src.Teacher.Id));

        }


        public Guid CreateGroup(SessionDto session, GroupBaseDto)
        {
            return Guid.NewGuid();
        }

        public bool AddStudentToGroup(SessionDto session, Guid groupId, Guid studentId)
        {
            return true;
        }

        public bool RemoveStudentFromGroup(SessionDto session, Guid studentId)
        {
            return true;
        }
              

        public Guid CreateExam(SessionDto session, ExamDto exam)
        {
            return Guid.NewGuid();
        }

        public bool PassExam(SessionDto session, Guid examId, Guid studentId, int mark, string comments)
        {
            return true;
        }        

        public bool RemoveGroup(SessionDto session, Guid groupId)
        {
            return true;
        }

        public GroupListDto GetGroups(SessionDto session)
        {            
            var grouplistdto = new GroupListDto();
            grouplistdto.Groups = Database.get().Groups.Select(group => Mapper.Map<GroupDto, GroupBaseDto>(group)).ToList();
            return grouplistdto;
        }

        public StudentListGuidsDto GetStudentsByGroup(SessionDto session, Guid groupId)
        {           
            var studentlistguidsdto = new StudentListGuidsDto();
            IEnumerable<GroupDto> query = Database.get().Groups.Where(group => group.Id.Equals(groupId));
            if (query.Count() != 0)
                studentlistguidsdto.Guids = query.First().StudentsGuids;
            else
                studentlistguidsdto.Guids = new List<Guid>(0);

            return studentlistguidsdto;
        }


        public ExamListDto GetExamResults(SessionDto session, Guid studentId)
        {
            ExamListDto _for_return = new ExamListDto();
            _for_return.StudentGuid = Database.TimurExams.Student.Id;
            _for_return.Exams = Database.TimurExams.Exams
                .Select(item => Mapper.Map<ExamWithSubjectAndTeacherDto, ExamDto>(item))
                .ToList();

            
            return _for_return;
        }
    }
}
